<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>分类: 技术教程 | 小小程序员</title><meta name="author" content="十一星野"><meta name="copyright" content="十一星野"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="平时使用 SpringBoot 开发项目，少不了要使用到它的注解。这些注解让我们摆脱了繁琐的传统 Spring XML 配置，让我们开发项目更加高效，今天我们就来聊聊 SpringBoot 中常用的注解！  #常用注解概览这里整理了一张SpringBoot常用注解的思维导图，本文主要讲解这些注解的用法。  #组件相关注解#@Controller用于修饰MVC中controller层的组件，Spr">
<meta property="og:type" content="article">
<meta property="og:title" content="肝了一周总结的SpringBoot常用注解大全，看完就炉火纯青了！">
<meta property="og:url" content="https://ko25891wan.gitlab.io/2024/01/4ec2ca7d89bb.html">
<meta property="og:site_name" content="小小程序员">
<meta property="og:description" content="平时使用 SpringBoot 开发项目，少不了要使用到它的注解。这些注解让我们摆脱了繁琐的传统 Spring XML 配置，让我们开发项目更加高效，今天我们就来聊聊 SpringBoot 中常用的注解！  #常用注解概览这里整理了一张SpringBoot常用注解的思维导图，本文主要讲解这些注解的用法。  #组件相关注解#@Controller用于修饰MVC中controller层的组件，Spr">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png">
<meta property="article:published_time" content="2024-01-21T09:28:26.000Z">
<meta property="article:modified_time" content="2024-02-02T13:41:38.490Z">
<meta property="article:author" content="十一星野">
<meta property="article:tag" content="宅男,热血">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://ko25891wan.gitlab.io/2024/01/4ec2ca7d89bb.html"><link rel="preconnect" href="//fastly.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.5.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":1,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.staticfile.org/egjs-infinitegrid/4.11.0/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '分类: 技术教程',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-02-02 21:41:38'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="小小程序员"><span class="site-name">小小程序员</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">肝了一周总结的SpringBoot常用注解大全，看完就炉火纯青了！</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-01-21T09:28:26.000Z" title="发表于 2024-01-21 17:28:26">2024-01-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-02-02T13:41:38.490Z" title="更新于 2024-02-02 21:41:38">2024-02-02</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/">技术教程</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/">mall</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/%E5%8F%82%E8%80%83%E7%AF%87/">参考篇</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">3.4k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>14分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="肝了一周总结的SpringBoot常用注解大全，看完就炉火纯青了！"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><blockquote>
<p>平时使用 SpringBoot 开发项目，少不了要使用到它的注解。这些注解让我们摆脱了繁琐的传统 Spring XML 配置，让我们开发项目更加高效，今天我们就来聊聊 SpringBoot 中常用的注解！</p>
</blockquote>
<h2 id="常用注解概览"><a href="#常用注解概览" class="headerlink" title="#常用注解概览"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#%E5%B8%B8%E7%94%A8%E6%B3%A8%E8%A7%A3%E6%A6%82%E8%A7%88">#</a>常用注解概览</h2><p>这里整理了一张SpringBoot常用注解的思维导图，本文主要讲解这些注解的用法。</p>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/springboot_annotation_mind-e2e60b14.png"></p>
<h2 id="组件相关注解"><a href="#组件相关注解" class="headerlink" title="#组件相关注解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#%E7%BB%84%E4%BB%B6%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3">#</a>组件相关注解</h2><h3 id="Controller"><a href="#Controller" class="headerlink" title="#@Controller"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#controller">#</a>@Controller</h3><p>用于修饰MVC中<code>controller</code>层的组件，SpringBoot中的组件扫描功能会识别到该注解，并为修饰的类实例化对象，通常与<code>@RequestMapping</code>联用，当SpringMVC获取到请求时会转发到指定路径的方法进行处理。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 后台用户管理Controller</span><br><span class="line"> * @date 2018/4/26</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Controller</span><br><span class="line">@RequestMapping(&quot;/admin&quot;)</span><br><span class="line">public class UmsAdminController &#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Service"><a href="#Service" class="headerlink" title="#@Service"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#service">#</a>@Service</h3><p>用于修饰<code>service</code>层的组件，<code>service</code>层组件专注于系统业务逻辑的处理，同样会被组件扫描并生成实例化对象。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 后台用户管理Service实现类</span><br><span class="line"> * @date 2018/4/26</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Service</span><br><span class="line">public class UmsAdminServiceImpl implements UmsAdminService &#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Repository"><a href="#Repository" class="headerlink" title="#@Repository"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#repository">#</a>@Repository</h3><p>用于修饰<code>dao</code>层的组件，<code>dao</code>层组件专注于系统数据的处理，例如数据库中的数据，同样会被组件扫描并生成实例化对象。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 后台用户与角色关系管理自定义Dao</span><br><span class="line"> * @date 2018/10/8</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Repository</span><br><span class="line">public interface UmsAdminRoleRelationDao &#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Component"><a href="#Component" class="headerlink" title="#@Component"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#component">#</a>@Component</h3><p>用于修饰SpringBoot中的组件，会被组件扫描并生成实例化对象。<code>@Controller</code>、<code>@Service</code>、<code>@Repository</code>都是特殊的组件注解。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 取消订单消息的生产者组件</span><br><span class="line"> * @date 2018/9/14</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Component</span><br><span class="line">public class CancelOrderSender &#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="依赖注入注解"><a href="#依赖注入注解" class="headerlink" title="#依赖注入注解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#%E4%BE%9D%E8%B5%96%E6%B3%A8%E5%85%A5%E6%B3%A8%E8%A7%A3">#</a>依赖注入注解</h2><h3 id="Autowired"><a href="#Autowired" class="headerlink" title="#@Autowired"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#autowired">#</a>@Autowired</h3><p>会根据对象的<code>类型</code>自动注入依赖对象，默认要求注入对象实例必须存在，可以配置<code>required=false</code>来注入不一定存在的对象。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 后台用户管理Controller</span><br><span class="line"> * @date 2018/4/26</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Controller</span><br><span class="line">@RequestMapping(&quot;/admin&quot;)</span><br><span class="line">public class UmsAdminController &#123;</span><br><span class="line">    @Autowired</span><br><span class="line">    private UmsAdminService adminService;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Resource"><a href="#Resource" class="headerlink" title="#@Resource"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#resource">#</a>@Resource</h3><p>默认会根据对象的<code>名称</code>自动注入依赖对象，如果想要根据类型进行注入，可以设置属性为<code>type = UmsAdminService.class</code>。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 后台用户管理Controller</span><br><span class="line"> * @date 2018/4/26</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Controller</span><br><span class="line">@RequestMapping(&quot;/admin&quot;)</span><br><span class="line">public class UmsAdminController &#123;</span><br><span class="line">    @Autowired</span><br><span class="line">    @Resource(name = &quot;umsAdminServiceImpl&quot;)</span><br><span class="line">    private UmsAdminService adminService;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Qualifier"><a href="#Qualifier" class="headerlink" title="#@Qualifier"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#qualifier">#</a>@Qualifier</h3><p>当同一个对象有多个实例可以注入时，使用<code>@Autowired</code>注解无法进行注入，这时可以使用<code>@Qualifier</code>注解指定实例的名称进行精确注入。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 后台用户管理Controller</span><br><span class="line"> * @date 2018/4/26</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Controller</span><br><span class="line">@RequestMapping(&quot;/admin&quot;)</span><br><span class="line">public class UmsAdminController &#123;</span><br><span class="line">    @Autowired</span><br><span class="line">    @Qualifier(&quot;umsAdminServiceImpl&quot;)</span><br><span class="line">    private UmsAdminService adminService;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="实例与生命周期相关注解"><a href="#实例与生命周期相关注解" class="headerlink" title="#实例与生命周期相关注解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#%E5%AE%9E%E4%BE%8B%E4%B8%8E%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3">#</a>实例与生命周期相关注解</h2><h3 id="Bean"><a href="#Bean" class="headerlink" title="#@Bean"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#bean">#</a>@Bean</h3><p>用于修饰方法，标识该方法会创建一个Bean实例，并交给Spring容器来管理。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description RestTemplate相关配置</span><br><span class="line"> * @date 2018/4/26</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Configuration</span><br><span class="line">public class RestTemplateConfig &#123;</span><br><span class="line">    @Bean</span><br><span class="line">    public RestTemplate restTemplate()&#123;</span><br><span class="line">        return new RestTemplate();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Scope"><a href="#Scope" class="headerlink" title="#@Scope"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#scope">#</a>@Scope</h3><p>用于声明一个Spring<code>Bean</code>实例的作用域，作用域的范围有以下几种：</p>
<ul>
<li>singleton：单例模式，在Spring容器中该实例唯一，Spring默认的实例模式。</li>
<li>prototype：原型模式，每次使用实例都将重新创建。</li>
<li>request：在同一请求中使用相同的实例，不同请求重新创建。</li>
<li>session：在同一会话中使用相同的实例，不同会话重新创建。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description RestTemplate相关配置</span><br><span class="line"> * @date 2018/4/26</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Configuration</span><br><span class="line">public class RestTemplateConfig &#123;</span><br><span class="line">    @Bean</span><br><span class="line">    @Scope(&quot;singleton&quot;)</span><br><span class="line">    public RestTemplate restTemplate()&#123;</span><br><span class="line">        return new RestTemplate();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Primary"><a href="#Primary" class="headerlink" title="#@Primary"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#primary">#</a>@Primary</h3><p>当同一个对象有多个实例时，优先选择该实例。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description Jackson相关配置，配置json不返回null的字段</span><br><span class="line"> * @date 2018/8/2</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Configuration</span><br><span class="line">public class JacksonConfig &#123;</span><br><span class="line">    @Bean</span><br><span class="line">    @Primary</span><br><span class="line">    @ConditionalOnMissingBean(ObjectMapper.class)</span><br><span class="line">    public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) &#123;</span><br><span class="line">        ObjectMapper objectMapper = builder.createXmlMapper(false).build();</span><br><span class="line">        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);</span><br><span class="line">        return objectMapper;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="PostConstruct"><a href="#PostConstruct" class="headerlink" title="#@PostConstruct"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#postconstruct">#</a>@PostConstruct</h3><p>用于修饰方法，当对象实例被创建并且依赖注入完成后执行，可用于对象实例的初始化操作。</p>
<h3 id="PreDestroy"><a href="#PreDestroy" class="headerlink" title="#@PreDestroy"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#predestroy">#</a>@PreDestroy</h3><p>用于修饰方法，当对象实例将被Spring容器移除时执行，可用于对象实例持有资源的释放。</p>
<h3 id="PostConstruct、-PreDestroy示例"><a href="#PostConstruct、-PreDestroy示例" class="headerlink" title="#@PostConstruct、@PreDestroy示例"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#postconstruct%E3%80%81-predestroy%E7%A4%BA%E4%BE%8B">#</a>@PostConstruct、@PreDestroy示例</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 动态权限数据源，用于获取动态权限规则</span><br><span class="line"> * @date 2020/2/7</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">public class DynamicSecurityMetadataSource implements FilterInvocationSecurityMetadataSource &#123;</span><br><span class="line"></span><br><span class="line">    private static Map&lt;String, ConfigAttribute&gt; configAttributeMap = null;</span><br><span class="line">    @Autowired</span><br><span class="line">    private DynamicSecurityService dynamicSecurityService;</span><br><span class="line"></span><br><span class="line">    @PostConstruct</span><br><span class="line">    public void loadDataSource() &#123;</span><br><span class="line">        configAttributeMap = dynamicSecurityService.loadDataSource();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @PostConstruct</span><br><span class="line">    public void loadDataSource() &#123;</span><br><span class="line">        configAttributeMap = dynamicSecurityService.loadDataSource();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @PreDestroy</span><br><span class="line">    public void clearDataSource() &#123;</span><br><span class="line">        configAttributeMap.clear();</span><br><span class="line">        configAttributeMap = null;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="SpringMVC相关注解"><a href="#SpringMVC相关注解" class="headerlink" title="#SpringMVC相关注解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#springmvc%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3">#</a>SpringMVC相关注解</h2><h3 id="RequestMapping"><a href="#RequestMapping" class="headerlink" title="#@RequestMapping"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#requestmapping">#</a>@RequestMapping</h3><p>可用于将Web请求路径映射到处理类的方法上，当作用于类上时，可以统一类中所有方法的路由路径，当作用于方法上时，可单独指定方法的路由路径。</p>
<p><code>method</code>属性可以指定请求的方式，如GET、POST、PUT、DELETE等。</p>
<h3 id="RequestBody"><a href="#RequestBody" class="headerlink" title="#@RequestBody"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#requestbody">#</a>@RequestBody</h3><p>表示方法的请求参数为JSON格式，从Body中传入，将自动绑定到方法参数对象中。</p>
<h3 id="ResponseBody"><a href="#ResponseBody" class="headerlink" title="#@ResponseBody"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#responsebody">#</a>@ResponseBody</h3><p>表示方法将返回JSON格式的数据，会自动将返回的对象转化为JSON数据。</p>
<h3 id="RequestParam"><a href="#RequestParam" class="headerlink" title="#@RequestParam"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#requestparam">#</a>@RequestParam</h3><p>用于接收请求参数，可以是如下三种形式：</p>
<ul>
<li>query param：GET请求拼接在地址里的参数。</li>
<li>form data：POST表单提交的参数。</li>
<li>multipart：文件上传请求的部分参数。</li>
</ul>
<h3 id="PathVariable"><a href="#PathVariable" class="headerlink" title="#@PathVariable"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#pathvariable">#</a>@PathVariable</h3><p>用于接收请求路径中的参数，常用于REST风格的API。</p>
<h3 id="RequestPart"><a href="#RequestPart" class="headerlink" title="#@RequestPart"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#requestpart">#</a>@RequestPart</h3><p>用于接收文件上传中的文件参数，通常是<code>multipart/form-data</code>形式传入的参数。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description MinIO对象存储管理Controller</span><br><span class="line"> * @date 2019/12/25</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Controller</span><br><span class="line">@RequestMapping(&quot;/minio&quot;)</span><br><span class="line">public class MinioController &#123;</span><br><span class="line"></span><br><span class="line">    @RequestMapping(value = &quot;/upload&quot;, method = RequestMethod.POST)</span><br><span class="line">    @ResponseBody</span><br><span class="line">    public CommonResult upload(@RequestPart(&quot;file&quot;) MultipartFile file) &#123;</span><br><span class="line">            //省略文件上传操作...</span><br><span class="line">            return CommonResult.success(minioUploadDto);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="SpringMVC注解示例"><a href="#SpringMVC注解示例" class="headerlink" title="#SpringMVC注解示例"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#springmvc%E6%B3%A8%E8%A7%A3%E7%A4%BA%E4%BE%8B">#</a>SpringMVC注解示例</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 后台用户管理Controller</span><br><span class="line"> * @date 2018/4/26</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Controller</span><br><span class="line">@RequestMapping(&quot;/admin&quot;)</span><br><span class="line">public class UmsAdminController &#123;</span><br><span class="line"></span><br><span class="line">    @RequestMapping(value = &quot;/register&quot;, method = RequestMethod.POST)</span><br><span class="line">    @ResponseBody</span><br><span class="line">    public CommonResult&lt;UmsAdmin&gt; register(@RequestBody UmsAdminParam umsAdminParam) &#123;</span><br><span class="line">        UmsAdmin umsAdmin = adminService.register(umsAdminParam);</span><br><span class="line">        if (umsAdmin == null) &#123;</span><br><span class="line">            return CommonResult.failed();</span><br><span class="line">        &#125;</span><br><span class="line">        return CommonResult.success(umsAdmin);</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    @RequestMapping(value = &quot;/list&quot;, method = RequestMethod.GET)</span><br><span class="line">    @ResponseBody</span><br><span class="line">    public CommonResult&lt;CommonPage&lt;UmsAdmin&gt;&gt; list(@RequestParam(value = &quot;keyword&quot;, required = false) String keyword,</span><br><span class="line">                                                   @RequestParam(value = &quot;pageSize&quot;, defaultValue = &quot;5&quot;) Integer pageSize,</span><br><span class="line">                                                   @RequestParam(value = &quot;pageNum&quot;, defaultValue = &quot;1&quot;) Integer pageNum) &#123;</span><br><span class="line">        List&lt;UmsAdmin&gt; adminList = adminService.list(keyword, pageSize, pageNum);</span><br><span class="line">        return CommonResult.success(CommonPage.restPage(adminList));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @RequestMapping(value = &quot;/&#123;id&#125;&quot;, method = RequestMethod.GET)</span><br><span class="line">    @ResponseBody</span><br><span class="line">    public CommonResult&lt;UmsAdmin&gt; getItem(@PathVariable Long id) &#123;</span><br><span class="line">        UmsAdmin admin = adminService.getItem(id);</span><br><span class="line">        return CommonResult.success(admin);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="RestController"><a href="#RestController" class="headerlink" title="#@RestController"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#restcontroller">#</a>@RestController</h3><p>用于表示<code>controller</code>层的组件，与<code>@Controller</code>注解的不同在于，相当于在每个请求处理方法上都添加了<code>@ResponseBody</code>注解，这些方法都将返回JSON格式数据。</p>
<h3 id="GetMapping"><a href="#GetMapping" class="headerlink" title="#@GetMapping"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#getmapping">#</a>@GetMapping</h3><p>用于表示GET请求方法，等价于<code>@RequestMapping(method = RequestMethod.GET)</code>。</p>
<h3 id="PostMapping"><a href="#PostMapping" class="headerlink" title="#@PostMapping"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#postmapping">#</a>@PostMapping</h3><p>用于表示POST请求方法，等价于<code>@RequestMapping(method = RequestMethod.POST)</code>。</p>
<h3 id="REST风格注解示例"><a href="#REST风格注解示例" class="headerlink" title="#REST风格注解示例"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#rest%E9%A3%8E%E6%A0%BC%E6%B3%A8%E8%A7%A3%E7%A4%BA%E4%BE%8B">#</a>REST风格注解示例</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 后台用户管理Controller</span><br><span class="line"> * @date 2018/4/26</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@RestController</span><br><span class="line">@RequestMapping(&quot;/admin&quot;)</span><br><span class="line">public class UmsAdminController &#123;</span><br><span class="line"></span><br><span class="line">    @PostMapping(&quot;/register&quot;)</span><br><span class="line">    public CommonResult&lt;UmsAdmin&gt; register(@RequestBody UmsAdminParam umsAdminParam) &#123;</span><br><span class="line">        UmsAdmin umsAdmin = adminService.register(umsAdminParam);</span><br><span class="line">        if (umsAdmin == null) &#123;</span><br><span class="line">            return CommonResult.failed();</span><br><span class="line">        &#125;</span><br><span class="line">        return CommonResult.success(umsAdmin);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @GetMapping(&quot;/list&quot;)</span><br><span class="line">    public CommonResult&lt;CommonPage&lt;UmsAdmin&gt;&gt; list(@RequestParam(value = &quot;keyword&quot;, required = false) String keyword,</span><br><span class="line">                                                   @RequestParam(value = &quot;pageSize&quot;, defaultValue = &quot;5&quot;) Integer pageSize,</span><br><span class="line">                                                   @RequestParam(value = &quot;pageNum&quot;, defaultValue = &quot;1&quot;) Integer pageNum) &#123;</span><br><span class="line">        List&lt;UmsAdmin&gt; adminList = adminService.list(keyword, pageSize, pageNum);</span><br><span class="line">        return CommonResult.success(CommonPage.restPage(adminList));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="配置相关注解"><a href="#配置相关注解" class="headerlink" title="#配置相关注解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#%E9%85%8D%E7%BD%AE%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3">#</a>配置相关注解</h2><h3 id="Configuration"><a href="#Configuration" class="headerlink" title="#@Configuration"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#configuration">#</a>@Configuration</h3><p>用于声明一个Java形式的配置类，SpringBoot推荐使用Java配置，在该类中声明的Bean等配置将被SpringBoot的组件扫描功能扫描到。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description MyBatis相关配置</span><br><span class="line"> * @date 2019/4/8</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Configuration</span><br><span class="line">@MapperScan(&#123;&quot;com.macro.mall.mapper&quot;,&quot;com.macro.mall.dao&quot;&#125;)</span><br><span class="line">public class MyBatisConfig &#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="EnableAutoConfiguration"><a href="#EnableAutoConfiguration" class="headerlink" title="#@EnableAutoConfiguration"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#enableautoconfiguration">#</a>@EnableAutoConfiguration</h3><p>启用SpringBoot的自动化配置，会根据你在<code>pom.xml</code>添加的依赖和<code>application-dev.yml</code>中的配置自动创建你需要的配置。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">@Configuration</span><br><span class="line">@EnableAutoConfiguration</span><br><span class="line">public class AppConfig &#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="ComponentScan"><a href="#ComponentScan" class="headerlink" title="#@ComponentScan"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#componentscan">#</a>@ComponentScan</h3><p>启用SpringBoot的组件扫描功能，将自动装配和注入指定包下的Bean实例。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">@Configuration</span><br><span class="line">@ComponentScan(&#123;&quot;xyz.erupt&quot;,&quot;com.macro.mall.tiny&quot;&#125;)</span><br><span class="line">public class EruptConfig &#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="SpringBootApplication"><a href="#SpringBootApplication" class="headerlink" title="#@SpringBootApplication"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#springbootapplication">#</a>@SpringBootApplication</h3><p>用于表示SpringBoot应用中的启动类，相当于<code>@EnableAutoConfiguration</code>、<code>@EnableAutoConfiguration</code>和<code>@ComponentScan</code>三个注解的结合体。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">@SpringBootApplication</span><br><span class="line">public class MallTinyApplication &#123;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        SpringApplication.run(MallTinyApplication.class, args);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="EnableCaching"><a href="#EnableCaching" class="headerlink" title="#@EnableCaching"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#enablecaching">#</a>@EnableCaching</h3><p>当添加Spring Data Redis依赖之后，可用该注解开启Spring基于注解的缓存管理功能。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description Redis配置类</span><br><span class="line"> * @date 2020/3/2</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@EnableCaching</span><br><span class="line">@Configuration</span><br><span class="line">public class RedisConfig extends BaseRedisConfig &#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="value"><a href="#value" class="headerlink" title="#@value"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#value">#</a>@value</h3><p>用于注入在配置文件中配置好的属性，例如我们可以在<code>application.yml</code>配置如下属性：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">jwt:</span><br><span class="line">  tokenHeader: Authorization #JWT存储的请求头</span><br><span class="line">  secret: mall-admin-secret #JWT加解密使用的密钥</span><br><span class="line">  expiration: 604800 #JWT的超期限时间(60*60*24*7)</span><br><span class="line">  tokenHead: &#x27;Bearer &#x27;  #JWT负载中拿到开头</span><br></pre></td></tr></table></figure>

<p>然后在Java类中就可以使用<code>@Value</code>注入并进行使用了。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">public class JwtTokenUtil &#123;</span><br><span class="line">    @Value(&quot;$&#123;jwt.secret&#125;&quot;)</span><br><span class="line">    private String secret;</span><br><span class="line">    @Value(&quot;$&#123;jwt.expiration&#125;&quot;)</span><br><span class="line">    private Long expiration;</span><br><span class="line">    @Value(&quot;$&#123;jwt.tokenHead&#125;&quot;)</span><br><span class="line">    private String tokenHead;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="ConfigurationProperties"><a href="#ConfigurationProperties" class="headerlink" title="#@ConfigurationProperties"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#configurationproperties">#</a>@ConfigurationProperties</h3><p>用于批量注入外部配置，以对象的形式来导入指定前缀的配置，比如这里我们在<code>application.yml</code>中指定了<code>secure.ignored</code>为前缀的属性：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">secure:</span><br><span class="line">  ignored:</span><br><span class="line">    urls: #安全路径白名单</span><br><span class="line">      - /swagger-ui/</span><br><span class="line">      - /swagger-resources/**</span><br><span class="line">      - /**/v2/api-docs</span><br><span class="line">      - /**/*.html</span><br><span class="line">      - /**/*.js</span><br><span class="line">      - /**/*.css</span><br><span class="line">      - /**/*.png</span><br><span class="line">      - /**/*.map</span><br><span class="line">      - /favicon.ico</span><br><span class="line">      - /actuator/**</span><br><span class="line">      - /druid/**</span><br></pre></td></tr></table></figure>

<p>然后在Java类中定义一个<code>urls</code>属性就可以导入配置文件中的属性了。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description SpringSecurity白名单资源路径配置</span><br><span class="line"> * @date 2018/11/5</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Getter</span><br><span class="line">@Setter</span><br><span class="line">@Configuration</span><br><span class="line">@ConfigurationProperties(prefix = &quot;secure.ignored&quot;)</span><br><span class="line">public class IgnoreUrlsConfig &#123;</span><br><span class="line"></span><br><span class="line">    private List&lt;String&gt; urls = new ArrayList&lt;&gt;();</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Conditional"><a href="#Conditional" class="headerlink" title="#@Conditional"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#conditional">#</a>@Conditional</h3><p>用于表示当某个条件满足时，该组件或Bean将被Spring容器创建，下面是几个常用的条件注解。</p>
<ul>
<li>@ConditionalOnBean：当某个Bean存在时，配置生效。</li>
<li>@ConditionalOnMissingBean：当某个Bean不存在时，配置生效。</li>
<li>@ConditionalOnClass：当某个类在Classpath存在时，配置生效。</li>
<li>@ConditionalOnMissingClass：当某个类在Classpath不存在时，配置生效。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description Jackson相关配置，配置json不返回null的字段</span><br><span class="line"> * @date 2018/8/2</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Configuration</span><br><span class="line">public class JacksonConfig &#123;</span><br><span class="line">    @Bean</span><br><span class="line">    @Primary</span><br><span class="line">    @ConditionalOnMissingBean(ObjectMapper.class)</span><br><span class="line">    public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) &#123;</span><br><span class="line">        ObjectMapper objectMapper = builder.createXmlMapper(false).build();</span><br><span class="line">        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);</span><br><span class="line">        return objectMapper;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="数据库事务相关注解"><a href="#数据库事务相关注解" class="headerlink" title="#数据库事务相关注解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#%E6%95%B0%E6%8D%AE%E5%BA%93%E4%BA%8B%E5%8A%A1%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3">#</a>数据库事务相关注解</h2><h3 id="EnableTransactionManagement"><a href="#EnableTransactionManagement" class="headerlink" title="#@EnableTransactionManagement"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#enabletransactionmanagement">#</a>@EnableTransactionManagement</h3><p>启用Spring基于注解的事务管理功能，需要和<code>@Configuration</code>注解一起使用。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description MyBatis相关配置</span><br><span class="line"> * @date 2019/4/8</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Configuration</span><br><span class="line">@EnableTransactionManagement</span><br><span class="line">@MapperScan(&#123;&quot;com.macro.mall.mapper&quot;,&quot;com.macro.mall.dao&quot;&#125;)</span><br><span class="line">public class MyBatisConfig &#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Transactional"><a href="#Transactional" class="headerlink" title="#@Transactional"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#transactional">#</a>@Transactional</h3><p>表示方法和类需要开启事务，当作用与类上时，类中所有方法均会开启事务，当作用于方法上时，方法开启事务，方法上的注解无法被子类所继承。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 前台订单管理Service</span><br><span class="line"> * @date 2018/8/30</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">public interface OmsPortalOrderService &#123;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 根据提交信息生成订单</span><br><span class="line">     */</span><br><span class="line">    @Transactional</span><br><span class="line">    Map&lt;String, Object&gt; generateOrder(OrderParam orderParam);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="SpringSecurity相关注解"><a href="#SpringSecurity相关注解" class="headerlink" title="#SpringSecurity相关注解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#springsecurity%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3">#</a>SpringSecurity相关注解</h2><h3 id="EnableWebSecurity"><a href="#EnableWebSecurity" class="headerlink" title="#@EnableWebSecurity"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#enablewebsecurity">#</a>@EnableWebSecurity</h3><p>启用SpringSecurity的Web功能。</p>
<h3 id="EnableGlobalMethodSecurity"><a href="#EnableGlobalMethodSecurity" class="headerlink" title="#@EnableGlobalMethodSecurity"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#enableglobalmethodsecurity">#</a>@EnableGlobalMethodSecurity</h3><p>启用SpringSecurity基于方法的安全功能，当我们使用<code>@PreAuthorize</code>修饰接口方法时，需要有对应权限的用户才能访问。</p>
<h3 id="SpringSecurity配置示例"><a href="#SpringSecurity配置示例" class="headerlink" title="#SpringSecurity配置示例"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#springsecurity%E9%85%8D%E7%BD%AE%E7%A4%BA%E4%BE%8B">#</a>SpringSecurity配置示例</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description SpringSecurity配置</span><br><span class="line"> * @date 2019/10/8</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Configuration</span><br><span class="line">@EnableWebSecurity</span><br><span class="line">@EnableGlobalMethodSecurity(prePostEnabled = true)</span><br><span class="line">public class SecurityConfig&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="全局异常处理注解"><a href="#全局异常处理注解" class="headerlink" title="#全局异常处理注解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#%E5%85%A8%E5%B1%80%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%E6%B3%A8%E8%A7%A3">#</a>全局异常处理注解</h2><h3 id="ControllerAdvice"><a href="#ControllerAdvice" class="headerlink" title="#@ControllerAdvice"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#controlleradvice">#</a>@ControllerAdvice</h3><p>常与<code>@ExceptionHandler</code>注解一起使用，用于捕获全局异常，能作用于所有controller中。</p>
<h3 id="ExceptionHandler"><a href="#ExceptionHandler" class="headerlink" title="#@ExceptionHandler"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#exceptionhandler">#</a>@ExceptionHandler</h3><p>修饰方法时，表示该方法为处理全局异常的方法。</p>
<h3 id="全局异常处理示例"><a href="#全局异常处理示例" class="headerlink" title="#全局异常处理示例"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#%E5%85%A8%E5%B1%80%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%E7%A4%BA%E4%BE%8B">#</a>全局异常处理示例</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 全局异常处理</span><br><span class="line"> * @date 2020/2/27</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@ControllerAdvice</span><br><span class="line">public class GlobalExceptionHandler &#123;</span><br><span class="line"></span><br><span class="line">    @ResponseBody</span><br><span class="line">    @ExceptionHandler(value = ApiException.class)</span><br><span class="line">    public CommonResult handle(ApiException e) &#123;</span><br><span class="line">        if (e.getErrorCode() != null) &#123;</span><br><span class="line">            return CommonResult.failed(e.getErrorCode());</span><br><span class="line">        &#125;</span><br><span class="line">        return CommonResult.failed(e.getMessage());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="AOP相关注解"><a href="#AOP相关注解" class="headerlink" title="#AOP相关注解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#aop%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3">#</a>AOP相关注解</h2><h3 id="Aspect"><a href="#Aspect" class="headerlink" title="#@Aspect"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#aspect">#</a>@Aspect</h3><p>用于定义切面，切面是通知和切点的结合，定义了何时、何地应用通知功能。</p>
<h3 id="Before"><a href="#Before" class="headerlink" title="#@Before"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#before">#</a>@Before</h3><p>表示前置通知（Before），通知方法会在目标方法调用之前执行，通知描述了切面要完成的工作以及何时执行。</p>
<h3 id="After"><a href="#After" class="headerlink" title="#@After"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#after">#</a>@After</h3><p>表示后置通知（After），通知方法会在目标方法返回或抛出异常后执行。</p>
<h3 id="AfterReturning"><a href="#AfterReturning" class="headerlink" title="#@AfterReturning"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#afterreturning">#</a>@AfterReturning</h3><p>表示返回通知（AfterReturning），通知方法会在目标方法返回后执行。</p>
<h3 id="AfterThrowing"><a href="#AfterThrowing" class="headerlink" title="#@AfterThrowing"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#afterthrowing">#</a>@AfterThrowing</h3><p>表示异常通知（AfterThrowing），通知方法会在目标方法返回后执行。</p>
<h3 id="Around"><a href="#Around" class="headerlink" title="#@Around"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#around">#</a>@Around</h3><p>表示环绕通知（Around），通知方法会将目标方法封装起来，在目标方法调用之前和之后执行自定义的行为。</p>
<h3 id="Pointcut"><a href="#Pointcut" class="headerlink" title="#@Pointcut"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#pointcut">#</a>@Pointcut</h3><p>定义切点表达式，定义了通知功能被应用的范围。</p>
<h3 id="Order"><a href="#Order" class="headerlink" title="#@Order"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#order">#</a>@Order</h3><p>用于定义组件的执行顺序，在AOP中指的是切面的执行顺序，value属性越低优先级越高。</p>
<h3 id="AOP相关示例"><a href="#AOP相关示例" class="headerlink" title="#AOP相关示例"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#aop%E7%9B%B8%E5%85%B3%E7%A4%BA%E4%BE%8B">#</a>AOP相关示例</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description 统一日志处理切面</span><br><span class="line"> * @date 2018/4/26</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@Aspect</span><br><span class="line">@Component</span><br><span class="line">@Order(1)</span><br><span class="line">public class WebLogAspect &#123;</span><br><span class="line">    private static final Logger LOGGER = LoggerFactory.getLogger(WebLogAspect.class);</span><br><span class="line"></span><br><span class="line">    @Pointcut(&quot;execution(public * com.macro.mall.tiny.controller.*.*(..))&quot;)</span><br><span class="line">    public void webLog() &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Before(&quot;webLog()&quot;)</span><br><span class="line">    public void doBefore(JoinPoint joinPoint) throws Throwable &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @AfterReturning(value = &quot;webLog()&quot;, returning = &quot;ret&quot;)</span><br><span class="line">    public void doAfterReturning(Object ret) throws Throwable &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Around(&quot;webLog()&quot;)</span><br><span class="line">    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable &#123;</span><br><span class="line">        WebLog webLog = new WebLog();</span><br><span class="line">        //省略日志处理操作...</span><br><span class="line">        Object result = joinPoint.proceed();</span><br><span class="line">        LOGGER.info(&quot;&#123;&#125;&quot;, JSONUtil.parse(webLog));</span><br><span class="line">        return result;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="测试相关注解"><a href="#测试相关注解" class="headerlink" title="#测试相关注解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#%E6%B5%8B%E8%AF%95%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3">#</a>测试相关注解</h2><h3 id="SpringBootTest"><a href="#SpringBootTest" class="headerlink" title="#@SpringBootTest"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#springboottest">#</a>@SpringBootTest</h3><p>用于指定测试类启用Spring Boot Test功能，默认会提供Mock环境。</p>
<h3 id="Test"><a href="#Test" class="headerlink" title="#@Test"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#test">#</a>@Test</h3><p>指定方法为测试方法。</p>
<h3 id="测试示例"><a href="#测试示例" class="headerlink" title="#测试示例"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#%E6%B5%8B%E8%AF%95%E7%A4%BA%E4%BE%8B">#</a>测试示例</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @auther macrozheng</span><br><span class="line"> * @description JUnit基本测试</span><br><span class="line"> * @date 2022/10/11</span><br><span class="line"> * @github https://github.com/macrozheng</span><br><span class="line"> */</span><br><span class="line">@SpringBootTest</span><br><span class="line">public class FirstTest &#123;</span><br><span class="line">    @Test</span><br><span class="line">    public void test() &#123;</span><br><span class="line">        int a=1;</span><br><span class="line">        Assertions.assertEquals(1,a);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="总结"><a href="#总结" class="headerlink" title="#总结"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/springboot_annotation.html#%E6%80%BB%E7%BB%93">#</a>总结</h2><p>这些SpringBoot注解基本都是我平时做项目常用的注解，在我的电商实战项目mall中基本都用到了，这里做了一番整理归纳，希望对大家有所帮助！</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io">十一星野</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io/2024/01/4ec2ca7d89bb.html">https://ko25891wan.gitlab.io/2024/01/4ec2ca7d89bb.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://ko25891wan.gitlab.io" target="_blank">小小程序员</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2024/01/1e0f014a2244.html" title="肝了一周总结的SpringBoot实战教程，太实用了！"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">肝了一周总结的SpringBoot实战教程，太实用了！</div></div></a></div><div class="next-post pull-right"><a href="/2024/01/6e44f3117e70.html" title="不要再重复造轮子了，这款开源工具类库贼好使！"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">不要再重复造轮子了，这款开源工具类库贼好使！</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">十一星野</div><div class="author-info__description">归途也还可爱</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io"><i class="fab fa-github"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Gitlab"><i class="fab fa-gitlab" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:ko25891wan@outlook.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E6%B3%A8%E8%A7%A3%E6%A6%82%E8%A7%88"><span class="toc-number">1.</span> <span class="toc-text">常用注解概览</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3"><span class="toc-number">2.</span> <span class="toc-text">组件相关注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Controller"><span class="toc-number">2.1.</span> <span class="toc-text">@Controller</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Service"><span class="toc-number">2.2.</span> <span class="toc-text">@Service</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Repository"><span class="toc-number">2.3.</span> <span class="toc-text">@Repository</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Component"><span class="toc-number">2.4.</span> <span class="toc-text">@Component</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BE%9D%E8%B5%96%E6%B3%A8%E5%85%A5%E6%B3%A8%E8%A7%A3"><span class="toc-number">3.</span> <span class="toc-text">依赖注入注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Autowired"><span class="toc-number">3.1.</span> <span class="toc-text">@Autowired</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Resource"><span class="toc-number">3.2.</span> <span class="toc-text">@Resource</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Qualifier"><span class="toc-number">3.3.</span> <span class="toc-text">@Qualifier</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E4%BE%8B%E4%B8%8E%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3"><span class="toc-number">4.</span> <span class="toc-text">实例与生命周期相关注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Bean"><span class="toc-number">4.1.</span> <span class="toc-text">@Bean</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Scope"><span class="toc-number">4.2.</span> <span class="toc-text">@Scope</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Primary"><span class="toc-number">4.3.</span> <span class="toc-text">@Primary</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#PostConstruct"><span class="toc-number">4.4.</span> <span class="toc-text">@PostConstruct</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#PreDestroy"><span class="toc-number">4.5.</span> <span class="toc-text">@PreDestroy</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#PostConstruct%E3%80%81-PreDestroy%E7%A4%BA%E4%BE%8B"><span class="toc-number">4.6.</span> <span class="toc-text">@PostConstruct、@PreDestroy示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringMVC%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3"><span class="toc-number">5.</span> <span class="toc-text">SpringMVC相关注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#RequestMapping"><span class="toc-number">5.1.</span> <span class="toc-text">@RequestMapping</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#RequestBody"><span class="toc-number">5.2.</span> <span class="toc-text">@RequestBody</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ResponseBody"><span class="toc-number">5.3.</span> <span class="toc-text">@ResponseBody</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#RequestParam"><span class="toc-number">5.4.</span> <span class="toc-text">@RequestParam</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#PathVariable"><span class="toc-number">5.5.</span> <span class="toc-text">@PathVariable</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#RequestPart"><span class="toc-number">5.6.</span> <span class="toc-text">@RequestPart</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SpringMVC%E6%B3%A8%E8%A7%A3%E7%A4%BA%E4%BE%8B"><span class="toc-number">5.7.</span> <span class="toc-text">SpringMVC注解示例</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#RestController"><span class="toc-number">5.8.</span> <span class="toc-text">@RestController</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#GetMapping"><span class="toc-number">5.9.</span> <span class="toc-text">@GetMapping</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#PostMapping"><span class="toc-number">5.10.</span> <span class="toc-text">@PostMapping</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#REST%E9%A3%8E%E6%A0%BC%E6%B3%A8%E8%A7%A3%E7%A4%BA%E4%BE%8B"><span class="toc-number">5.11.</span> <span class="toc-text">REST风格注解示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3"><span class="toc-number">6.</span> <span class="toc-text">配置相关注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Configuration"><span class="toc-number">6.1.</span> <span class="toc-text">@Configuration</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#EnableAutoConfiguration"><span class="toc-number">6.2.</span> <span class="toc-text">@EnableAutoConfiguration</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ComponentScan"><span class="toc-number">6.3.</span> <span class="toc-text">@ComponentScan</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SpringBootApplication"><span class="toc-number">6.4.</span> <span class="toc-text">@SpringBootApplication</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#EnableCaching"><span class="toc-number">6.5.</span> <span class="toc-text">@EnableCaching</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#value"><span class="toc-number">6.6.</span> <span class="toc-text">@value</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ConfigurationProperties"><span class="toc-number">6.7.</span> <span class="toc-text">@ConfigurationProperties</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Conditional"><span class="toc-number">6.8.</span> <span class="toc-text">@Conditional</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E4%BA%8B%E5%8A%A1%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3"><span class="toc-number">7.</span> <span class="toc-text">数据库事务相关注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#EnableTransactionManagement"><span class="toc-number">7.1.</span> <span class="toc-text">@EnableTransactionManagement</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Transactional"><span class="toc-number">7.2.</span> <span class="toc-text">@Transactional</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringSecurity%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3"><span class="toc-number">8.</span> <span class="toc-text">SpringSecurity相关注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#EnableWebSecurity"><span class="toc-number">8.1.</span> <span class="toc-text">@EnableWebSecurity</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#EnableGlobalMethodSecurity"><span class="toc-number">8.2.</span> <span class="toc-text">@EnableGlobalMethodSecurity</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SpringSecurity%E9%85%8D%E7%BD%AE%E7%A4%BA%E4%BE%8B"><span class="toc-number">8.3.</span> <span class="toc-text">SpringSecurity配置示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%A8%E5%B1%80%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%E6%B3%A8%E8%A7%A3"><span class="toc-number">9.</span> <span class="toc-text">全局异常处理注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#ControllerAdvice"><span class="toc-number">9.1.</span> <span class="toc-text">@ControllerAdvice</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ExceptionHandler"><span class="toc-number">9.2.</span> <span class="toc-text">@ExceptionHandler</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%A8%E5%B1%80%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%E7%A4%BA%E4%BE%8B"><span class="toc-number">9.3.</span> <span class="toc-text">全局异常处理示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#AOP%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3"><span class="toc-number">10.</span> <span class="toc-text">AOP相关注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Aspect"><span class="toc-number">10.1.</span> <span class="toc-text">@Aspect</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Before"><span class="toc-number">10.2.</span> <span class="toc-text">@Before</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#After"><span class="toc-number">10.3.</span> <span class="toc-text">@After</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#AfterReturning"><span class="toc-number">10.4.</span> <span class="toc-text">@AfterReturning</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#AfterThrowing"><span class="toc-number">10.5.</span> <span class="toc-text">@AfterThrowing</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Around"><span class="toc-number">10.6.</span> <span class="toc-text">@Around</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Pointcut"><span class="toc-number">10.7.</span> <span class="toc-text">@Pointcut</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Order"><span class="toc-number">10.8.</span> <span class="toc-text">@Order</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#AOP%E7%9B%B8%E5%85%B3%E7%A4%BA%E4%BE%8B"><span class="toc-number">10.9.</span> <span class="toc-text">AOP相关示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95%E7%9B%B8%E5%85%B3%E6%B3%A8%E8%A7%A3"><span class="toc-number">11.</span> <span class="toc-text">测试相关注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#SpringBootTest"><span class="toc-number">11.1.</span> <span class="toc-text">@SpringBootTest</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Test"><span class="toc-number">11.2.</span> <span class="toc-text">@Test</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95%E7%A4%BA%E4%BE%8B"><span class="toc-number">11.3.</span> <span class="toc-text">测试示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">12.</span> <span class="toc-text">总结</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/c60470b9a892.html" title="Java集合使用注意事项总结">Java集合使用注意事项总结</a><time datetime="2024-02-03T04:58:22.000Z" title="发表于 2024-02-03 12:58:22">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/81fb7a201f29.html" title="无题">无题</a><time datetime="2024-02-03T03:15:31.812Z" title="发表于 2024-02-03 11:15:31">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/5737c1ec69a9.html" title="Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)">Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)</a><time datetime="2024-01-31T06:56:16.000Z" title="发表于 2024-01-31 14:56:16">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/f510db7d2f19.html" title="Spring常见面试题总结">Spring常见面试题总结</a><time datetime="2024-01-31T06:55:58.000Z" title="发表于 2024-01-31 14:55:58">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/9be065e9f288.html" title="redis 面试">redis 面试</a><time datetime="2024-01-31T06:55:55.000Z" title="发表于 2024-01-31 14:55:55">2024-01-31</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2023 - 2024 By 十一星野</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.staticfile.org/instant.page/5.2.0/instantpage.min.js" type="module"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>